/*
 * @Author: hfWang
 * @Date: 2022-07-18 23:11:14
 * @LastEditTime: 2022-09-14 21:47:02
 * @Description: file content
 * @FilePath: \hf-blog-2\docs\.vitepress\customConfig\getOtherSeries.ts
 */

import * as fs from "fs";
import type { DefaultTheme } from "vitepress";
import { titleMap } from '../constant'

const cwd = process.cwd();
const targetPath = `${cwd}/docs`;
const dirs = fs.readdirSync(targetPath, { encoding: "utf8" });
const targetDir = dirs.filter((item) =>
	!["index.md", ".vitepress", "public"].includes(item)
);

// 获取其他分类
const getOtherSeries = (
	filterName: string,
	noShowSeries: string[] = ["interView"]
): DefaultTheme.SidebarGroup => {

	const _targetDir = targetDir.filter(item =>
		![filterName, ...noShowSeries].includes(item)
	)

	let allSeries: DefaultTheme.SidebarItem[] = [];

	_targetDir.map((item) => {
		allSeries.push({
			text: titleMap[item] || item,
			link: `/${item}/`,
		});
	});

	const otherSeries = {
		text: "其他系列",
		collapsible: true,
		collapsed: true,
		items: allSeries,
	};
	return otherSeries;
};

export default getOtherSeries;
